<template>
    <el-dialog title="增加余额" :visible.sync="show" center width="30%"
               :before-close="close">
        <el-form v-model="form"  label-width="120px">
            <el-form-item label="余额">
                <el-input v-model.number="form.balance"></el-input>
            </el-form-item>
            <el-form-item label="金币">
                <el-input v-model.number="form.coin"></el-input>
            </el-form-item>
            <el-form-item label="增加原因">
            <el-input type="textarea" v-model="form.reason" autosize placeholder="请填写原因"></el-input>
        </el-form-item>
            <el-form-item>
                <el-button :loading="loading" @click="close">取 消</el-button>
                <el-button :loading="loading" type="primary" @click="submit">确 定</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
export default {
    name: "UserRich",
    props: {
        show: false,
        user_id: 0,
    },
    data() {
        return {
            loading: false,
            form: {
                reason: '',
                balance: 0,
                coin: 0,
            }
        }
    },
    watch: {
        show(val) {
            if (!val) this.$emit('close');
        }
    },
    methods: {
        close() {
            this.$emit('close');
        },
        submit() {
            this.form['id'] = this.user_id
            let form = this.form
            this.$store.dispatch('user/Rich', form).then(res => {
                this.$message.success(res.data.message);
                this.$emit('submit');
            }).finally(() => {
                this.$emit('close');
            });
        }
    }
}
</script>

<style scoped>

</style>
